﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Asistente.Serialization;
using Asistente.Model.Representation;
using Asistente.Managers;

namespace Asistente.Test
{
    [TestClass]
    public class SerializerTests
    {
        [TestMethod]
        public void TestSerializationAndDeserialization()
        {
            const string path =@"C:\Temp\DemoSerialization.XML";

            var app = new Application();

            var user = new Entity();
            
            //Una entidad
            user.Name = "User";
            app.Entities.Add(user);

            //Dos casos de uso
            UseCase login = UseCaseManager.Instance.NewUseCase(UseCasePattern.Login,user);
            app.UseCases.Add(login);
            UseCase passChange = UseCaseManager.Instance.GetPasswordChange(user);
            app.UseCases.Add(passChange);

            //Se serializa
            Serializer.Instance.Serialize(app, path);

            //Obtenemos la aplicacion
            Application deserializeAp = Serializer.Instance.Deserialize(path);
            Assert.AreEqual(2, deserializeAp.UseCases.Count);
            Assert.AreEqual("Login1", deserializeAp.UseCases[0].Name);
            Assert.AreEqual("PasswordChange1", deserializeAp.UseCases[1].Name);
        }
    }
}
